Group Legends
- SAB - shock AB
- SAA - shock AA
- CAB - context AB
- CAA - context AA
Channel Legend
- Ch 1 = DAPI (stained)
- Ch 2 = GFP (experience 1)
- Ch 3 = GFAP (stained)
- Ch 4 = ARC (experience 2; stained)
- OL = overlap GFP/Arc
- OL.norm = overlap normalized to GFP/Arc
EXPT legends
- AGE 10 = young mice
- AGE 11 = old mice
Prepare the data
- loads the libraries
- loads the data (as kk)
- merges in the animal details
- creates a normalized measure of OL counts
- transforms a long format version of data (kk.long)
# Load libraries
library(ggplot2)
library(reshape2)
library(dplyr)
library(plotrix)
library(GGally)
# Load the data
kk = read.csv(file="All AGE 10 series counts-03232018/Wes_SUBROI_CLN_STACKED.csv", header=TRUE, sep=",")
kk$idBysubroi = as.factor(kk$idBysubroi)
# Merge animal details
animal_details = read.csv("animal_details.csv")
animal_details$Mouse.ID. = as.factor(animal_details$ID)
colnames(animal_details)[9] = "idBysubroi"
kk = merge(animal_details, kk, by = "idBysubroi")
colnames(kk)[2] = "GROUP"
# Merge group details
group_details = read.csv("group_details.csv")
names(group_details)[1] = "GROUP" # because for some reason it messes up
kk = merge(group_details, kk, by="GROUP")
replace = read.csv("replacements.csv")
names(replace) = c("pre", "post") # because for some reason the names mess up
# Rename the age groups
kk$EXPT = as.factor(as.character(replace$post[match(kk$EXPT, replace$pre)]))
# normalize the OL counts
kk$OLmm2.norm = kk$OLmm2
kk$OLmm2.norm = kk$OLmm2/(kk$Ch2mm2 + kk$Ch4mm2 - kk$OLmm2)
# Rename all variable names of the channels
names(kk)[15:20] = as.character(replace[1:6,2])
attach(kk)
# Transform rawkk to a long format
kk.long = melt(kk, id.vars=names(kk[1:14]), variable.name = "CHANNEL", value.name="DENSITY")
Create table of data to find the mean and SEM for for each: roi, group, age
- Summarize a new table where each obs is an animal with unweighted average density for whole brain
- Then plot so that each error bar reflects number of animals ## Results here:
- DAPI counts are fairly similar between young/age groups
- Every other channel is different between young/age animals
- How do we know for sure that the young/age don’t have technical artifacts?
- Old animals consistently have higher densities, what are possible reasons? – [] double check that the imaging parameters are the same – [] find the mean INTENSITY in each of these groups – [] if we only include the brightest z-plane, can we alleviate this? – []
#
# # What is the mean count per brain, normalized to area?
# channels.all = names(kk[15:20])
kkl.collapseROI = kk.long %>%
group_by(CHANNEL, GROUP, VALENCE, CONTEXT, EXPT, ID) %>%
summarize(sem = std.error(DENSITY), mean_density = mean(DENSITY), N = length(DENSITY),
ymin = mean_density-sem, ymax = mean_density+sem)
kkl.collapseROI
## # A tibble: 312 x 11
## # Groups: CHANNEL, GROUP, VALENCE, CONTEXT, EXPT [?]
## CHANNEL GROUP VALENCE CONTEXT EXPT ID sem mean_density N
## <fct> <fct> <fct> <fct> <fct> <int> <dbl> <dbl> <int>
## 1 DAPI CAA CONTEXT AA _YOUNG 8358 21.7 286. 72
## 2 DAPI CAA CONTEXT AA _YOUNG 9214 54.0 1128. 72
## 3 DAPI CAA CONTEXT AA _YOUNG 9221 15.8 241. 72
## 4 DAPI CAA CONTEXT AA _YOUNG 9222 53.9 545. 72
## 5 DAPI CAA CONTEXT AA _YOUNG 9224 25.1 714. 72
## 6 DAPI CAA CONTEXT AA _YOUNG 9265 30.8 551. 72
## 7 DAPI CAA CONTEXT AA _YOUNG 9278 26.2 620. 72
## 8 DAPI CAA CONTEXT AA OLD 3539 27.8 869. 72
## 9 DAPI CAA CONTEXT AA OLD 3540 32.7 624. 72
## 10 DAPI CAA CONTEXT AA OLD 3541 22.0 343. 72
## # ... with 302 more rows, and 2 more variables: ymin <dbl>, ymax <dbl>
ggplot(kkl.collapseROI) + aes(GROUP, mean_density, fill=EXPT, color = EXPT) + facet_wrap(~CHANNEL, scales="free") +
stat_summary(fun.y = mean, geom="point") +
stat_summary(fun.data = mean_se, geom="linerange") +
ggtitle("Comparing densities per channel ~ group/age, where n = # animals ")

ggplot(kkl.collapseROI) + aes(VALENCE, mean_density, fill=EXPT, color = EXPT) + facet_wrap(~CHANNEL, scales="free") +
stat_summary(fun.y = mean, geom="point") +
stat_summary(fun.data = mean_se, geom="linerange") +
ggtitle("--- comparing context vs. shock")

ggplot(kkl.collapseROI) + aes(CONTEXT, mean_density, fill=EXPT, color = EXPT) + facet_wrap(~CHANNEL, scales="free") +
stat_summary(fun.y = mean, geom="point") +
stat_summary(fun.data = mean_se, geom="linerange") +
ggtitle("--- comparing A/A vs. A/B")

Look means at each SUBROI
- not sure where these SEMs are correct
# for (i in channels.all) {
# print (
# ggplot(rawkk) + aes(factor(SUBROI), rawkk[i], fill=EXPT, color=EXPT) +
# stat_summary(fun.y = mean,
# position="dodge",
# geom="point") +
# stat_summary(fun.data = mean_se,
# size=.5,
# position="dodge",
# geom="linerange") +
# ggtitle(i) + coord_flip()
# )
# }
kkl.collapseID = kk.long %>%
group_by(CHANNEL, GROUP, EXPT, SUBROI, ID) %>%
summarize(sem = std.error(DENSITY), mean_density = mean(DENSITY), N = length(DENSITY),
ymin = mean_density-sem, ymax = mean_density+sem)
kkl.collapseID
## # A tibble: 22,464 x 10
## # Groups: CHANNEL, GROUP, EXPT, SUBROI [?]
## CHANNEL GROUP EXPT SUBROI ID sem mean_density N ymin ymax
## <fct> <fct> <fct> <fct> <int> <dbl> <dbl> <int> <dbl> <dbl>
## 1 DAPI CAA _YOUNG AcB 8358 NA 193. 1 NA NA
## 2 DAPI CAA _YOUNG AcB 9214 NA 1361. 1 NA NA
## 3 DAPI CAA _YOUNG AcB 9221 NA 234. 1 NA NA
## 4 DAPI CAA _YOUNG AcB 9222 NA 1139. 1 NA NA
## 5 DAPI CAA _YOUNG AcB 9224 NA 432. 1 NA NA
## 6 DAPI CAA _YOUNG AcB 9265 NA 650. 1 NA NA
## 7 DAPI CAA _YOUNG AcB 9278 NA 825. 1 NA NA
## 8 DAPI CAA _YOUNG AI 8358 NA 72.2 1 NA NA
## 9 DAPI CAA _YOUNG AI 9214 NA 1736. 1 NA NA
## 10 DAPI CAA _YOUNG AI 9221 NA 99.6 1 NA NA
## # ... with 22,454 more rows
ggplot(kkl.collapseID) + aes(SUBROI, mean_density, fill=EXPT, color=EXPT) +
stat_summary(fun.y = mean, geom = "point") +
stat_summary(fun.data = mean_se, size=0.5, geom="linerange") +
coord_flip() + facet_wrap(GROUP~CHANNEL, ncol=6, scales="free")

ggplot(filter(kk.long, kk.long$CHANNEL=="OLmm2.norm")) + aes(SUBROI, DENSITY, fill=EXPT, color=EXPT) +
stat_summary(fun.y = mean, geom = "point") +
stat_summary(fun.data = mean_se, size=0.5, geom="linerange") +
ggtitle("OLmm2 normalized to Arc and GFP") + coord_flip()

For loop for each ROI
- Make a graph and the data table separately
for (k in channels.all) {
for (roi in interesting.ROI) {
df = rawkk[rawkk$SUBROI %in% list(roi),]
# Make pointrange graphs
print(
ggplot(df) +
aes(x=GROUP, y=df[,k], fill=EXPT, shape=EXPT, color=EXPT) +
stat_summary(fun.y = mean,
geom="point") +
stat_summary(fun.data=mean_se,
geom="pointrange") +
facet_wrap(~SUBROI) +
labs(y = as.character(k)) +
ggtitle(paste0(roi, " for channel ", k))
)
#
# # let's check if we can summarize the table by dplyr
# print(
# rawkk[rawkk$SUBROI==roi,] %>%
# group_by(GROUP, EXPT) %>%
# summarize_if(is.numeric, mean)
# )
# print(
# rawkk[rawkk$SUBROI==roi,] %>%
# group_by(GROUP, EXPT) %>%
# summarize_if(is.numeric, std.error)
# )
}
}
Which ROI are most reliable? Areamm2 by ROI
- I’d say biggest ROI are most reliable
ggplot(kk) + aes(x=reorder(SUBROI, AREAmm2), AREAmm2) + coord_flip() +
stat_summary(fun.y = mean, geom="point") +
ggtitle("ROI Area measured as proxy for reliability")
